import Vue from "vue";
import App from "./App.vue";
import Vant from "vant";
import "vant/lib/index.css";
import { IndexList, IndexSection } from "mint-ui";
import { Sku } from "vant";
import MintUI from "mint-ui";
import "mint-ui/lib/style.css";
import router from "./router";
import { isLogined } from "./utils/tools";

Vue.config.productionTip = false;
Vue.use(MintUI);
Vue.use(Vant);
Vue.use(Sku);
Vue.component(IndexList.name, IndexList);
Vue.component(IndexSection.name, IndexSection);
new Vue({
  render: (h) => h(App),
  router,
}).$mount("#app");

//路由全局守卫
router.beforeEach((to, from, next) => {
  console.log(to, from, next);
  if (to.meta.needLogin) {
    if (isLogined()) {
      next();
    } else {
      next({
        name: "Login",
      });
    }
  } else {
    next();
  }
});
//后置钩子 通俗的讲就是把着最后一关，
router.afterEach((to, from) => {
  console.log(to, from);
  // alert("我进来了");
});
